﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Common
{
    public class RuntimeException : ApplicationException
    {
        public int ErrorCode
        {
            get;
            set;
        }

        public RuntimeException()
        {
        }

        public RuntimeException( string msg )
            : this( int.MinValue, msg )
        {
        }

        public RuntimeException( int errorCode, string msg )
            : this( errorCode, msg, null )
        {

        }

        public RuntimeException( int errorCode, string msg, Exception innerException )
            : base( msg, innerException )
        {
            this.ErrorCode = errorCode;
        }

        protected RuntimeException( SerializationInfo info, StreamingContext context )
            : base( info, context )
        {
        }

        public string ToErrorString()
        {
            if( this.ErrorCode == int.MinValue )
            {
                return this.Message;
            }
            else
            {
                return string.Format( "{0}:{1}", this.ErrorCode, this.Message );
            }
        }
    }
}
